package com.androidx.p013lv.mine.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.UserAccount;
import com.androidx.p013lv.base.bean.event.CanWatchVipEvent;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.model.UserInfoModel;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.DeviceIDUtils;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.bean.PayBean;
import com.androidx.p013lv.mine.bean.RechargeBean;
import com.androidx.p013lv.mine.bean.VipCenterBean;
import com.androidx.p013lv.mine.databinding.VipCenterFragmentBinding;
import com.androidx.p013lv.mine.dialog.DialogVipBuyFailure;
import com.androidx.p013lv.mine.dialog.DialogVipBuySuccess;
import com.androidx.p013lv.mine.model.VipCenterModel;
import com.google.gson.Gson;
import java.util.List;
import java.util.Objects;
import org.greenrobot.eventbus.EventBus;

/* renamed from: com.androidx.lv.mine.fragment.VipCenterFragment */
public class VipCenterFragment extends LazyFragment<VipCenterFragmentBinding> implements View.OnClickListener {
    int addGoldNum;
    RechargeBean bean;
    private OnClick click;
    private DialogVipBuyFailure dialogFailure;
    String dialogMessage;
    private VipCenterModel model;
    int source;
    private UserAccount userAccount;
    private UserInfoModel userInfoModel;
    private VipCenterModel userModel;

    public static VipCenterFragment newInstance() {
        Bundle bundle = new Bundle();
        VipCenterFragment vipCenterFragment = new VipCenterFragment();
        vipCenterFragment.setArguments(bundle);
        return vipCenterFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.source = bundle.getInt("data");
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.vip_center_fragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        RechargeBean rechargeBean = new RechargeBean();
        this.bean = rechargeBean;
        rechargeBean.setSource(this.source);
        ((VipCenterFragmentBinding) this.binding).setBean(this.bean);
        this.click = new OnClick();
        ((VipCenterFragmentBinding) this.binding).setClick(this.click);
        VipCenterModel vipCenterModel = (VipCenterModel) new ViewModelProvider(this).get(VipCenterModel.class);
        this.model = vipCenterModel;
        vipCenterModel.dataAccount().observe(this, new Observer<BaseRes<UserAccount>>() {
            /* class com.androidx.p013lv.mine.fragment.VipCenterFragment.C13401 */

            public void onChanged(BaseRes<UserAccount> baseRes) {
                if (baseRes.getCode() == 200) {
                    VipCenterFragment.this.userAccount = baseRes.getData();
                    ((VipCenterFragmentBinding) VipCenterFragment.this.binding).setUserAccount(VipCenterFragment.this.userAccount);
                    SpUtils.getInstance().setUserAccount(VipCenterFragment.this.userAccount);
                }
            }
        });
        ViewGroup.LayoutParams layoutParams = ((VipCenterFragmentBinding) this.binding).f334b.getLayoutParams();
        layoutParams.width = (UiUtils.getWindowWidth() - UiUtils.dp2px(36)) / 2;
        ((VipCenterFragmentBinding) this.binding).f334b.setLayoutParams(layoutParams);
        ViewGroup.LayoutParams layoutParams2 = ((VipCenterFragmentBinding) this.binding).f333a.getLayoutParams();
        layoutParams2.width = (UiUtils.getWindowWidth() - UiUtils.dp2px(36)) / 2;
        ((VipCenterFragmentBinding) this.binding).f333a.setLayoutParams(layoutParams2);
        this.userAccount = SpUtils.getInstance().getUserAccount();
        this.userModel = (VipCenterModel) new ViewModelProvider((ViewModelStoreOwner) Objects.requireNonNull(getActivity())).get(VipCenterModel.class);
        this.userInfoModel = (UserInfoModel) new ViewModelProvider((ViewModelStoreOwner) Objects.requireNonNull(getActivity())).get(UserInfoModel.class);
        this.model.dataPay().observe(this, new Observer<BaseRes<PayBean>>() {
            /* class com.androidx.p013lv.mine.fragment.VipCenterFragment.C13412 */

            public void onChanged(BaseRes<PayBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    if (VipCenterFragment.this.bean.getRechType() == 0) {
                        UserAccount userAccount = VipCenterFragment.this.userAccount;
                        double bala = VipCenterFragment.this.userAccount.getBala();
                        double money = (double) VipCenterFragment.this.bean.getMoney();
                        Double.isNaN(money);
                        userAccount.setBala(bala - money);
                        if (VipCenterFragment.this.bean.getPurType() == 3) {
                            VipCenterFragment.this.userAccount.setGold(VipCenterFragment.this.userAccount.getGold() + VipCenterFragment.this.addGoldNum);
                        }
                        SpUtils.getInstance().setUserAccount(VipCenterFragment.this.userAccount);
                        ((VipCenterFragmentBinding) VipCenterFragment.this.binding).setUserAccount(VipCenterFragment.this.userAccount);
                        VipCenterFragment.this.userModel.changeUserAccount(VipCenterFragment.this.userAccount);
                        DialogVipBuySuccess dialogVipBuySuccess = new DialogVipBuySuccess((Context) Objects.requireNonNull(VipCenterFragment.this.getContext()));
                        if (VipCenterFragment.this.bean.getPurType() == 3) {
                            dialogVipBuySuccess.setMessage("恭喜您，購買" + VipCenterFragment.this.dialogMessage + "成功！");
                        } else {
                            EventBus.getDefault().post(new CanWatchVipEvent());
                            VipCenterFragment.this.userInfoModel.getUserInfo();
                            dialogVipBuySuccess.setMessage("恭喜您，開通會員成功！");
                        }
                        dialogVipBuySuccess.show();
                        return;
                    }
                    PayBean data = baseRes.getData();
                    ARouter.getInstance().build(Constance.RECHARGE_HINT_ACTIVITY).navigation();
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(Uri.parse(data.getUrl()));
                        VipCenterFragment.this.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                        ToastUtils.getInstance().showWeak("支付失敗");
                    }
                } else if (VipCenterFragment.this.bean.getRechType() == 0) {
                    VipCenterFragment.this.dialogFailure = new DialogVipBuyFailure((Context) Objects.requireNonNull(VipCenterFragment.this.getContext()));
                    VipCenterFragment.this.dialogFailure.setOnClickListener(VipCenterFragment.this);
                    VipCenterFragment.this.dialogFailure.show();
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setVipType(List<VipCenterBean.TypesBean> list) {
        int i = 0;
        ((VipCenterFragmentBinding) this.binding).setAliPay(0);
        ((VipCenterFragmentBinding) this.binding).setWeChat(0);
        ((VipCenterFragmentBinding) this.binding).setYsf(0);
        if (list == null || list.size() <= 0) {
            this.bean.setRechType(0);
            if (this.userAccount.getBala() < ((double) this.bean.getMoney())) {
                i = 1;
            }
            ((VipCenterFragmentBinding) this.binding).setCommitStatus(Integer.valueOf(i));
            return;
        }
        boolean z = false;
        boolean z2 = false;
        boolean z3 = false;
        for (VipCenterBean.TypesBean typesBean : list) {
            String payMent = typesBean.getPayMent();
            char c = 65535;
            switch (payMent.hashCode()) {
                case 1507424:
                    if (payMent.equals("1001")) {
                        c = 0;
                        break;
                    }
                    break;
                case 1507425:
                    if (payMent.equals("1002")) {
                        c = 1;
                        break;
                    }
                    break;
                case 1507426:
                    if (payMent.equals("1003")) {
                        c = 2;
                        break;
                    }
                    break;
            }
            if (c == 0) {
                ((VipCenterFragmentBinding) this.binding).setAliPay(1);
                z2 = true;
            } else if (c == 1) {
                ((VipCenterFragmentBinding) this.binding).setWeChat(1);
                z = true;
            } else if (c == 2) {
                ((VipCenterFragmentBinding) this.binding).setYsf(1);
                z3 = true;
            }
        }
        if (z) {
            this.bean.setRechType(2);
            ((VipCenterFragmentBinding) this.binding).setCommitStatus(0);
        } else if (z2) {
            this.bean.setRechType(1);
            ((VipCenterFragmentBinding) this.binding).setCommitStatus(0);
        } else if (z3) {
            this.bean.setRechType(3);
            ((VipCenterFragmentBinding) this.binding).setCommitStatus(0);
        } else {
            this.bean.setRechType(0);
            if (this.userAccount.getBala() < ((double) this.bean.getMoney())) {
                i = 1;
            }
            ((VipCenterFragmentBinding) this.binding).setCommitStatus(Integer.valueOf(i));
        }
    }

    public void onClick(View view) {
        DialogVipBuyFailure dialogVipBuyFailure;
        if (view.getId() == C1207R.C1210id.dialog_btn_sure && (dialogVipBuyFailure = this.dialogFailure) != null) {
            dialogVipBuyFailure.dismiss();
            this.click.commitPay();
        }
    }

    /* renamed from: com.androidx.lv.mine.fragment.VipCenterFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void switchPay(int i) {
            VipCenterFragment.this.bean.setRechType(i);
            int i2 = 0;
            if (i == 0 && VipCenterFragment.this.userAccount.getBala() < ((double) VipCenterFragment.this.bean.getMoney())) {
                i2 = 1;
            }
            ((VipCenterFragmentBinding) VipCenterFragment.this.binding).setCommitStatus(Integer.valueOf(i2));
        }

        public void commitPay() {
            if (!NetUtil.isNetworkAvailable()) {
                ToastUtils.getInstance().showWeak(UiUtils.getString(C1207R.string.hit_no_net));
            } else if (VipCenterFragment.this.bean.getRechType() == -1) {
                ToastUtils.getInstance().showSigh("請選擇支付型別");
            } else if (VipCenterFragment.this.bean.getMoney() == 0) {
                ToastUtils.getInstance().showSigh("請選擇購買商品");
            } else {
                VipCenterFragment.this.bean.setDeviceId(DeviceIDUtils.getUniqueId((Context) Objects.requireNonNull(VipCenterFragment.this.getContext())));
                VipCenterFragment.this.model.rechargePay(new Gson().toJson(VipCenterFragment.this.bean), VipCenterFragment.this.getContext());
            }
        }
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        this.model.userAccList(getContext());
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        VipCenterModel vipCenterModel = this.model;
        if (vipCenterModel != null) {
            vipCenterModel.cancelHttp();
        }
        VipCenterModel vipCenterModel2 = this.userModel;
        if (vipCenterModel2 != null) {
            vipCenterModel2.cancelHttp();
        }
        UserInfoModel userInfoModel2 = this.userInfoModel;
        if (userInfoModel2 != null) {
            userInfoModel2.cancelHttp();
        }
        super.onDestroyView();
    }
}
